package material.iteratorAndComponent.caffee;

import material.iteratorAndComponent.MenuItem;
import material.iteratorAndComponent.interal.Menu;

import java.util.Hashtable;
import java.util.Iterator;

public class CafeMenu implements Menu {
    Hashtable menuItems = new Hashtable();

    public CafeMenu() {
        addItem("Vegggie Burger and Air Fries", "tomato fries", true, 3.99);
        addItem("Soup the day", "with side salad", false, 3.69);
    }

    public void addItem(String name, String description, boolean vegetarian, double price) {
        MenuItem menuItem = new MenuItem(name, description, vegetarian, price);
        menuItems.put(menuItem.getName(), menuItem);
    }

    @Override
    public Iterator createIterator() {
        /**
         * 虽然HashTable和ArrayList相比复杂很多，
         * 因为它的每一个数据都是由一个key和一个value组成，尽管如此我们仍然可以获取值
         */
        return menuItems.values().iterator();
    }
}
